var mongoose = require('mongoose');
const config =  require('./config/config').default;
import autoIncrement from 'mongoose-auto-increment';

/**
 * 新增Option
 */
const options = {
    useMongoClient: true,
    useNewUrlParser: true,
    reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
    reconnectInterval: 500, // Reconnect every 500ms
    poolSize: 10, // Maintain up to 10 socket connections
    bufferMaxEntries: 0
};

export const connection1 = mongoose.createConnection(config.mongodb.url);
autoIncrement.initialize(connection1);

mongoose.Promise = global.Promise;

mongoose.connect(config.mongodb.url, options);

mongoose.connection.on("error", function (error) {
    console.log("connection failed! error：" + error)
});

mongoose.connection.on("open", function () {
    console.log("------connection success！------")
});

mongoose.connection.on('disconnected', function () {
    console.log('Mongoose connection disconnected');
});

module.exports = mongoose;